import ajax from '@/utils/ajax'

const user = {
  state: {
    name: '',
    isBinding: false
  },

  mutations: {
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_ISBINDING: (state, isBinding) => {
      state.isBinding = isBinding
    }
  },

  actions: {
    // 登出
    LogOut({ commit, state }) {
      return new Promise((resolve, reject) => {
        ajax.getData(process.env.BASE_API + '/logout').then(function(res) {
          if (res.errCode === 1) {
            sessionStorage.clear()
            window.location.reload()
            resolve()
          }
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default user
